USE [CASASHOW]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SP10_CONSULTA_COMPRA]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[SP10_CONSULTA_COMPRA]
GO

/****** Object:  StoredProcedure [dbo].[SP10_CONSULTA_COMPRA]    Script Date: 11/19/2013 12:02:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[SP10_CONSULTA_COMPRA]
	   @ID_COMPRA INT
AS
/******      Declaracao das variaveis locais - NUNCA utilize os parametros de entrada nos comandos SQL 
*/

DECLARE @V_ID_COMPRA INT
SET @V_ID_COMPRA = @ID_COMPRA

/******      Crie a logica da procedure abaixo
*/

IF @V_ID_COMPRA IS NULL  
BEGIN
	SELECT ID_COMPRA,ID_INGRESSO,ID_USUARIO,QT_INGRESSO
	FROM TB06_COMPRA
END
ELSE
BEGIN
	SELECT ID_COMPRA,ID_INGRESSO,ID_USUARIO,QT_INGRESSO
	FROM TB06_COMPRA TB06
	WHERE TB06.ID_COMPRA = @V_ID_COMPRA
END
